<HTML>
<HEAD>
<TITLE>Quake Demo</TITLE>

<script type="text/javascript">
<!--
var nacl_elt_a;
var nacl_elt_b;
var nacl_elt_c;

// Before scripting the loaded module, ensure the Native Client module is loaded.

var Completion = function(files_array) {
  var i;

  this.seen = new Array();
  this.files = files_array;
  this.num_left = files_array.length;

  for (i = 0; i < this.num_left; ++i) {
    this.seen[i] = 0;
  }

  this.done = function(name) {
    var i;

    for (i = 0; i < this.files.length; ++i) {
      if (this.seen[i]) {
        continue;
      }
      if (name == this.files[i]) {
        this.seen[i] = 1;
        --this.num_left;
        break;
      }
    }
    return (0 == this.num_left) ? 1 : 0;
  }
}

var FileLoadCallback = function(nacl_elt, filename, url, completion_pred) {
  this.filename = filename;
  this.url = url;
  this.pred = completion_pred;

  this.onload = function(nacl_desc) {
    nacl_elt.file(this.filename, nacl_desc, this.pred.done(this.filename));
  }
  this.onfail = function(object) {
    window.alert('Failed to load URL: ' + this.url + ', error ' + object);
  }
}

var StartLoad = function(nacl_elt, filename, url, comp) {
  nacl_elt.__urlAsNaClDesc(url,
                           new FileLoadCallback(nacl_elt, filename, url, comp));
}

var PostLoadInit = function(nacl_elt) {
  if (nacl_elt.__moduleReady == 1) {
    clearTimeout(nacl_elt.timeout);
    var load_array = new Array('./id1/pak0.pak');
    var comp = new Completion(load_array);
    var i;
    for (i = 0; i < load_array.length; ++i) {
      StartLoad(nacl_elt, load_array[i], load_array[i], comp);
    }
  } else {
    if (nacl_elt.__moduleReady == undefined) {
      window.alert('The Native Client plugin was unable to load');
      return;
    }
    var functRef = function() {
      PostLoadInit(nacl_elt);
    }
    nacl_elt.timeout = setTimeout(functRef, 100);
  }
}

// doOnLoad is called when the document has completed loading.
// This will then load & launch the NativeClient executables.
var doOnLoad = function() {
  // service_url contains the location of the NativeClient module to be
  // loaded as a service.
  nacl_elt_a = document.getElementById('embed_a');
  nacl_elt_b = document.getElementById('embed_b');
  nacl_elt_c = document.getElementById('embed_c');
  var delayInit = function(nacl_elt) {
    return function() { PostLoadInit(nacl_elt); }
  }
  // stagger instances of quake for smoother startup & level loads
  nacl_elt_a.timeout = setTimeout(delayInit(nacl_elt_a), 1000);
  nacl_elt_b.timeout = setTimeout(delayInit(nacl_elt_b), 3000);
  nacl_elt_c.timeout = setTimeout(delayInit(nacl_elt_c), 5000);
  nacl_elt_a.focus();
}

var doOnUnload = function() {
  // cancel any pending loads
  if (nacl_elt_a != null) clearTimeout(nacl_elt_a.timeout);
  if (nacl_elt_b != null) clearTimeout(nacl_elt_b.timeout);
  if (nacl_elt_c != null) clearTimeout(nacl_elt_c.timeout);
}
-->
</script>

</HEAD>
<BODY onload="doOnLoad();" onunload="doOnUnload();" id="bodyId" bgcolor="#333333" >
<span style="color:CCCCCC">
 <h1>Native Client Quake Demo (Stress Test)</h1>
 <span style="color:999999">
  <p>
     This demo is a 3-way stress test.  Please see quake.html for the normal version.
  </p>
  <p>
     Quake, a classic first person shooter released in 1996 by Id Software.
     Now open source, this demo is playable in the browser as a Native Client
     module.
  </p>
  <p>
     Click the game area below to give it keyboard focus, then press the
     spacebar to activate the game menu.  Select single player (hit return
     to select) then select new game.  Controls: arrow keys to move, space
     to jump, control key to fire, numeric keys to select various weapons
     aquired along the way.  Audio is also supported on systems with audio
     drivers installed.  Multiplayer mode is not supported.  Loading and
     saving game progress is not supported.
  </p>
 </span>
</span>
<center>
 <embed id="embed_a" src="nacl_quake" type="application/x-nacl-srpc" width=512 height=384 />
 <embed id="embed_b" src="nacl_quake" type="application/x-nacl-srpc" width=512 height=384 />
 <br>
 <embed id="embed_c" src="nacl_quake" type="application/x-nacl-srpc" width=512 height=384 />
</center>
<br>


</BODY>
</HTML>

